package com.lagou.util;

public class MonitorData {

    /**
     * 总调用次数
     */
    int totalInvokeTime = 0;
    /**
     * 调用耗时
     */
    int[] scale = new int[10000];
    /**
     * 调用次数
     */
    int[] countContainer = new int[10000];


    synchronized public void addTime(int ms) {
        totalInvokeTime++;
        scale[ms] = ms;
        countContainer[ms]++;
    }

    /**
     * 计算TP
     */
    public int countTP(float f) {
        int round = Math.round(totalInvokeTime * f);
        int result = 0;
        int invokeTime = 0;
        for (int i = 0; i < countContainer.length; i++) {
            invokeTime += countContainer[i];
            if (invokeTime >= round) {
                result = scale[i];
                break;
            }
        }
        return result;
    }

}
